package WorkQueue;

import Utils.ConnectionFactoryUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName Cosumer02
 * @Description TDD
 * @Author 混沌酱
 * @Date 2023-10-09 14:56
 * @Version 1.0
 **/
public class Cosumer02 {

    public static void main(String[] args) throws IOException, TimeoutException {

        // 1、创建工程连接
        Connection connection= ConnectionFactoryUtil.getConnection();

        // 2、连接信道
        Channel channel=connection.createChannel();

        // 3、监听队列处理消息
        DefaultConsumer defaultConsumer=new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                super.handleDelivery(consumerTag, envelope, properties, body);
                String message=new String(body,"UTF-8");
                System.out.println(message);
            }
        };

        channel.basicConsume("work_queue",true,defaultConsumer);
    }
}
